package problem53;

//53.最大子数组和
//https://leetcode.cn/problems/maximum-subarray/

class Solution {
    public int maxSubArray(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n];
        dp[0] = nums[0];
        int ret = dp[0];
        for(int i = 1; i<n; i++) {
            dp[i] = Math.max(dp[i-1]+nums[i], nums[i]);
            ret = Math.max(ret, dp[i]);
        }
        return ret;
    }
}

/*

dp[i]: 以第i个元素为结尾的最大子数组和

*/